package com.hlingsoft.kkh.action.v11;

import com.hlingsoft.kkh.action.BaseAction;
import com.hlingsoft.kkh.dao.EventCommentsDao;
import com.hlingsoft.kkh.dao.ImageDao;
import com.hlingsoft.kkh.entity.EventComments;
import com.hlingsoft.kkh.entity.Image;
import com.hlingsoft.kkh.util.Common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.*;

/**
 * Created by selbylei on 2015/4/15.
 */

@Controller

public class updateAction extends BaseAction {

    @Autowired
    private EventCommentsDao eventCommentsDao;
    @Autowired
    private ImageDao imageDao;



    @RequestMapping("/update.json")
    @ResponseBody
    public Map<String, Object> update(
            @RequestParam(value = "userId") long userId,
            HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
          List<EventComments> eventCommentsList =  eventCommentsDao.getAll();
          for (EventComments eventComments:eventCommentsList){
              String images = eventComments.getImage();
              List<String> imageList = Common.strToList(images);
              for (String image:imageList){
                  Image image1 = new Image();
                  image1.setEventsId(eventComments.getEventId());
                  image1.setEventCommentsId(eventComments.getId());
                  image1.setPath(image);
                  image1.setAppUserId(eventComments.getAppUserId());
                  image1.setCreateTime(eventComments.getCreateTime());
                  image1.setUpdateTime(eventComments.getCreateTime());
                  image1.setAvailable(1);
                  imageDao.addImage(image1);
              }

              resultMap.put("result", true);

          }
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
        }
        return resultMap;
    }
}
